package com.virus.coronavirus.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author: Bbeginner
 * @Date: 2022/2/1 17:52
 * @Version 1.0
 **/
@Configuration
public class CorsConfig implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**") //哪些接口URL需要增加跨域设置
//                .allowedOrigins("*")  //报错
                .allowedOriginPatterns("*") //前端哪些域名被允许跨域
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")    // 配置跨域请求支持的方式
                .allowCredentials(true)    // 配置是否允许发送Cookie，用于 凭证请求， 默认不发送cookie
                .maxAge(3600)
                .allowedHeaders("*");
    }
}
